#ifndef PROTOCOLS_ROCE_SENDER_MANAGER_H_
#define PROTOCOLS_ROCE_SENDER_MANAGER_H_

#include <stdint.h>
#include <vector>
#include <memory>
#include <unordered_map>
#include "ai_sim.h"
#define CLEAR_ACKED_SEGMENT_THRESHOLD 5000
namespace ai_sim {

struct SegmentInfo {
  // ai_sim::Flow * theFlow;
  SegmentInfo(){}
  SegmentInfo(Flow _flow, bool _last, uint32_t _seqNum, int _segSize) {
    flow = _flow;
    isLastSegment = _last;
    seqNum = _seqNum;
    segmentSize = _segSize;
  }
  Flow flow;
  bool isLastSegment;
  uint32_t seqNum;
  int segmentSize;
};

class RoceSenderManager {
public:
  RoceSenderManager(int mss);
  SegmentInfo* getNextSegment();
  void putLargeChunk(const ai_sim::Flow& flow);
  void handleAck(uint32_t seqNum);
  void handleNack(uint32_t seqNum);
  bool isSendCompleted();
private:
  void sliceChunk(const ai_sim::Flow& flow);
  void doClear();
private:
  
  uint32_t curMaxPktSeq;
  int sendMss; // send maxiunm segment size
  // std::vector<SegmentInfo> segments;
  uint32_t sendNext;
  uint32_t sendUna;
  std::unordered_map<uint32_t, SegmentInfo> segments;
  int lastClearedSeq;
};

} //

#endif